<?php

/*
 * Database Class
 * 
 * Interaction with the database
 * 
 * @author : Jason Meulenhoff
 * @mail : mail@kacangboi.com
 * @web : http://kacangboi.com
 * @copyright : KacangNetworks 2010
 * 
 */

class database
{
	private $query;
	
	public function __construct()
	{
		debug::message("Database instance created","INFO");
	}
	public function execute($query)
	{
		debug::message("Executing Database Command {$query}","INFO");
		if(DEBUG)
		{
			echo $query;
		}
		$this->query = mysql_query($query);
		
		debug::message("Command executed","INFO");
	}
	public function rowsFound()
	{
		debug::message("Looking for rows","INFO","");
		if(mysql_num_rows($this->query) > 0)
		{
			debug::message("Selected Row found returning results","INFO");
			return true;
		}
		else
		{
			debug::message("No rows found","INFO");
			return false;	
		}
	}
	public function countRows()
	{
		debug::message("counting rows","INFO");
		return mysql_num_rows($this->query);
	}
	public function saveAsObject()
	{
		debug::message("Saving all rows as objects","INFO");
		return mysql_fetch_object($this->query);
	}
	public function saveRow()
	{
		debug::message("Saving row into an array","INFO");
		return mysql_fetch_assoc($this->query);		
	}
	public function saveAllRows()
	{
		debug::message("Saving all rows in an array","INFO");
		$array = array();
		while($temp = mysql_fetch_assoc($this->query))
			array_push($array,$temp);
		return $array;
	}
}